package com.labraff.todo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class TaskListView extends AppCompatActivity {
    ListView lv_taskList;
    TextView tv_taskListTitle;
    globalApplication app;
    int taskType;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task_list_view);
        app = ((globalApplication)getApplication());

        // 视图绑定
        lv_taskList = findViewById(R.id.lv_taskList);
        tv_taskListTitle  = findViewById(R.id.tv_taskListTitle);
        init();

    }

    void init (){
        Intent intent = getIntent();
        this.taskType = intent.getIntExtra("taskType",0);
        taskList_adapter adapter;
        if(this.taskType==0){
            tv_taskListTitle.setText("待办清单");
            adapter = new taskList_adapter(this,app.getUndoTaskList(),this.taskType);
        }else{
            tv_taskListTitle.setText("达成任务");
            adapter = new taskList_adapter(this,app.getDoneTaskList(),this.taskType);
        }
        lv_taskList.setAdapter(adapter);
        lv_taskList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                task currentTask = app.getTaskList().get(position);
                Toast.makeText(TaskListView.this,currentTask.getTitle(),Toast.LENGTH_SHORT).show();
            }
        });
    }
}